﻿@model DateTime
@{
    ViewBag.Title = "任务日历";
}
<table class="noline">
    <tr style="border: 1px solid #7F9DB9; background-color: #7F9DB9; height:45px; color:#fff;">
        <td>
            <div style="width: 380px; float:left; margin-top:5px; margin-left:20px;">
                <label for="type">
                </label>
                @Html.Label("", "项目: ") @Html.DropDownList("projectfilter", new[] { new SelectListItem() { Text = "-请选择-", Value = "" } }, new { style = "width:145px;", @class = "projectfilter" })
                @Html.Label("", "成员: ")@Html.DropDownList("memberfilter", new[] { new SelectListItem() { Text = "-请选择-", Value = "" } }, new { style = "width:145px;", @class = "memberfilter" })
            </div>
            <div style="float: left; margin-top:5px;">
                @Html.Telerik().DatePicker().Name("dt").Value(DateTime.Now).ClientEvents(events => events.OnChange("dtonChange"))
            </div>
            <div class="colorArea">
                <div>
                    <span style="background: #01ad0d"></span>&nbsp;已完成
                </div>
                <div>
                    <span style="background: #d88201"></span>&nbsp;请审核
                </div>
                <div>
                    <span style="background: #5847bc"></span>&nbsp;进行中
                </div>
                <div>
                    <span style="background: #f2140f"></span>&nbsp;已过期
                </div>
                <div>
                    <span style="background: #696766"></span>&nbsp;取消/失败
                </div>
                <div>
                    <span style="background: #ffffff"></span>&nbsp;未开始
                </div>
            </div>
        </td>
    </tr>
    <tr align="center">
    </tr>
</table>
<div id="PartialCalendar">
</div>
@(Html.Telerik().Window().Title("任务信息")
    .Name("TastMessage")
    .Content(@<text><div class="dialogue-TastMessage">
        <div class="TastMessage-wrapper">
        </div>
    </div></text>)
    .Width(1050)
    .Height(550)
    .Modal(true).Visible(false).Draggable(true)
)
<script type="text/javascript">
    $(function () {
        initialProjectMemberfilter();
        getRole();
    });

    function freshFullCalendar(project, memberfilter, dt) {
        $.post('FullCalendar/freshFullCalendar', { searchProject: project, searchValue: memberfilter, searchdt: formatDate(dt) }, function (result) {
            $('#PartialCalendar').html(result);
        });
    }

    $(".projectfilter").change(function () {
        var project = $(this).closest(".projectfilter").val();
        var dt = $('#dt').data("tDatePicker").value();
        freshFullCalendar(project, "", dt);
    });

    $(".memberfilter").change(function () {
        var project = $(".projectfilter").val();
        var memberfilter = $(this).closest(".memberfilter").find("option:selected")[0].text;
        var dt = $('#dt').data("tDatePicker").value();
        freshFullCalendar(project, memberfilter, dt);
    });

    function getRole() {
        var selec = "0";
        var url = "/TimeLine/GetRole/";
        $.post(url, { 'taskLineID': selec }, function (data) {
            if (data == "任务执行者") {
                $("#tdone").hide();
                $("#trone").hide();
            }
        });
    }

    function dtonChange(e) {
        var project = $(".projectfilter").val();
        var memberfilter = $(".memberfilter").find("option:selected")[0].text;
        var dt = $('#dt').data("tDatePicker").value();
        freshFullCalendar(project, memberfilter, dt);
    }

    function formatDate(date) {
        return $.telerik.formatString('{0:ddMMyyyy}', date);
    }

    function showtask(id) {
        $.post('Task/GetDetail/', { taskid: id }, function (result) {
            $('.TastMessage-wrapper').html(result);
            var window = $('#TastMessage').data('tWindow');
            window.center().open();
        });
    }

    function initialProjectMemberfilter() {
        $(".projectfilter").change(function () {
            var projectid = $(this).val();
            var $member = $(this).parent().find(".memberfilter");
            $member.children().remove();
            $member.append("<option value=''>-请选择-</option>");
            $.post("/FullCalendar/memberfilter", { projectid: projectid }, function (result) {
                if (result) {
                    for (var i = 0; i < result.length; i++) {
                        $member.append("<option value='" + result[i].val + "'>" + result[i].text + "</option>");
                    }
                }
            })
        });
        $(".projectfilter").children().remove();
        $(".projectfilter").append("<option value=''>-请选择-</option>");
        $.post("/FullCalendar/projectfilter", function (result) {
            if (result) {
                for (var i = 0; i < result.length; i++) {
                    var val = result[i].value;
                    var text = result[i].text;
                    $(".projectfilter").append("<option value='" + val + "'>" + text + "</option>");
                }
            }
        })
    }
</script>
<style type="text/css">
    .noline
    {
        border: 1px solid #aaa;
        width: 100%;
        margin-top: 9px;
    }
    .colorArea
    {
        font-size: 12px;
        border: 0;
        float:right;
        margin-right:20px;
        margin-top:5px;
     }
    .colorArea div
    {
        float:left;
        margin-left:5px;
    }
    .colorArea div span
    {
        padding:3px 5px;
        margin-left:10px;
    }
    .colorArea tr, .colorArea td
    {
        border: 0;
    }
    #dt
    {
        height: 14px;
    }
    .noline, .noline tr, .noline td
    {
        border: 0px;
    }
</style>
